from typing import List, Optional

from pydantic import BaseModel, Field

from app.schemas.file_info import FileInfoVo


class CategoryVo(BaseModel):
    """返回分类数据时的模型(包含所有字段,用于接口响应)"""
    category_id: int = Field(..., alias='categoryId', description="分类ID(主键)")
    name: str = Field(..., alias='name', description="分类名称")
    parent_id: int = Field(..., alias='parentId', description="父分类ID")
    image_id: int = Field(..., alias='imageId', description="分类图片ID")
    status: int = Field(..., alias='status', description="分类状态")
    sort: int = Field(..., alias='sort', description="分类排序权重")
    image: Optional["FileInfoVo"] = None
    children: List["CategoryVo"] = Field(default_factory=list)

    # 配置：允许从ORM对象(如SQLAlchemy查询结果)直接转换为Pydantic模型
    class Config:
        orm_mode = True
